using ll = long long;
class Solution {
public:
    long long maximumOr(vector<int>& nums, int k) {
        int n = nums.size();
        vector<ll> left(n), right(n);
        left[0] = 0, right[n - 1] = 0;
        for (int i = 1; i < n; i++)
            left[i] = left[i - 1] | nums[i - 1];
        for (int i = n - 2; i >= 0; i--)
            right[i] = right[i + 1] | nums[i + 1];
        ll ans = 0;
        for (int i = 0; i < n; i++) {
            // cout << (((ll)nums[i] << k) | (left[i] | right[i])) << ' ';
            ans = max(ans, ((ll)nums[i] << k) | (left[i] | right[i]));
        }
        return ans;
    }
};